<template>
	<div id="content">
		<Header />
		<div class="login">
			<div class="right">
				<h5>注册</h5>
				<div class="input-box">
					<div class="input">
						<div class="name">账号</div>
						<input type="text" placeholder="请输入账号" v-model="username">
					</div>
					<div class="input">
						<div class="name">手机号码</div>
						<input type="number" placeholder="请输入手机号" v-model="phone">
					</div>
					<div class="input">
						<div class="name">登录密码</div>
						<input type="password" placeholder="请输入密码" v-model="password">
					</div>
					<div class="input">
						<div class="name">确认密码</div>
						<input type="password" placeholder="请再次输入密码" v-model="rawPassword">
					</div>
				
					<div class="login-btn" @click="confirm()">
						确定
					</div>
				</div>
			</div>
		</div>
		<Contact />
	</div>

</template>

<script>
import Header from '@/components/Header';
import Contact from '@/components/Contact';
import { forget } from "@/api/website";

export default {
	data() {
		return {
			username: "",
			phone: "",
			password: "",
			rawPassword: "",
		}
	},
	components: {
		Header,
		Contact
	},
	created() {

	},
	methods: {
		confirm() {
			if (!this.username) {
				this.$modal.msgError("请输入帐号");
				return
			}
			if (!this.phone) {
				this.$modal.msgError("请输入手机号");
				return
			}
			if(/^1\d{10}$/.test(this.phone) == false){
				this.$modal.msgError("请输入正确手机号");
				return
			}
			if (!this.password) {
				this.$modal.msgError("请输入密码");
				return
			}
			if(/^[a-zA-Z0-9]{6}$/.test(this.password) == false){
				this.$modal.msgError("请输入六位字母数字混合密码");
				return
			}
			if (!this.rawPassword) {
				this.$modal.msgError("请输入密码");
				return
			}

			if (this.rawPassword != this.password) {
				this.$modal.msgError("确认密码有误");
				return
			}
			if(this.username == this.phone){
				this.$modal.msgError("账号与手机号不能相同");
				return
			}
			forget({
				"username": this.username,
				"phone": this.phone,
				"password": this.password,
				"rawPassword": this.rawPassword,
			}).then(response => {
				this.$router.push('/portal/login');
			});
		}
	}
};
</script>

<style scoped lang="scss"></style>